package com.shd.edanpei.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.shd.edanpei.R;
import com.shd.edanpei.base.BaseActivity;
import com.shd.edanpei.presenter.OpinionPresenter;
import com.shd.edanpei.presenter.contract.OpinionContract;

import butterknife.BindView;
import butterknife.OnClick;

public class OpinionActivity extends BaseActivity<OpinionPresenter>
        implements OpinionContract.OpinionIView {


    @BindView(R.id.headline)
    TextView headline;
    @BindView(R.id.tv_headline_right)
    TextView tvRight;
    @BindView(R.id.et_feedbank_content)
    EditText etContent;
    @BindView(R.id.tv_feedbank_sum)
    TextView tvSum;

    @Override
    protected int setLayout() {
        return R.layout.activity_feedbank;
    }

    @Override
    protected OpinionPresenter bindPresenter() {
        return new OpinionPresenter(this);
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        headline.setText("意见反馈");
        tvRight.setText("反馈记录");
        tvRight.setVisibility(View.VISIBLE);
//        //检查是否存在草稿
//        String data = Preference.getData(OPINION);
//        if (null != data) {
//            etContent.setText(data);
//            etContent.setSelection(data.length());
//        }
////        //弹出键盘
//        ScreenUtils.showKeyboard(etContent);
    }

    @Override
    protected void initListener() {
        etContent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                tvSum.setText(s.length() + getResources().getString(R.string.feedbank_max));
                //意见存入草稿
//                Preference.setData(OPINION, s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    @OnClick(R.id.tv_headline_right)
    void onRecord() {
        startActivity(OpinionRecordActivity.class);
    }

    @OnClick(R.id.tv_submit)
    void submit() {
        mPresenter.submit(etContent.getText().toString());
    }

    @OnClick(R.id.iv_headline_back)
    void onBack() {
        finish();
    }


}
